<?
	include_once('header.php');

	include_once('sidebar.php');

	$action = $_GET['action'];
	$this_item = $_GET['item'];
	$id = $_GET['id'];
	if(get_magic_quotes_gpc()) {
		$this_item = stripslashes($this_item); 
	}
?>

		
		<div id="main">
			
			<h2>Gallery</h2>
<?
	if(!drizzo_user_is_allowed('gallery-write') || drizzo_global_options('module_gallery') != 1) {
		echo "<br class=\"clear\" /><p>This module is not available.</p><br class=\"clear\" />";
		include_once('footer.php');
		exit();
	}
?>

			<br class="clear" />
<?
	if($action == 'edit') {
		if($_POST) {
			if(drizzo_post_save()) {
				drizzo_media_update();
				echo "<p class=\"save\">" . drizzo_db_unwrap($_POST['title']) . " has been saved.</p>\n";
			} else {
				echo "<p class=\"save\">" . drizzo_db_unwrap($_POST['title']) . " has been saved.</p>\n";
			}
		} else {
			$the_post = drizzo_get_the_post($id);
?>
			<form id="editor_form" name="editor" method="post" action="">

			<div id="editor">
		
				<label for="title">Title</label><input name="title" type="text" value="<? echo drizzo_post_title(); ?>"></input><br />

				<label for="content">Description</label><textarea name="content" id="post_content"><? echo drizzo_post_content_backend(); ?></textarea><br />

				<label for="tags">Tags<br /><small>(Separate by commas)</small></label><textarea name="tags" type="text" id="tags_input"><? echo drizzo_post_tags($edit, "comma", "false"); if(drizzo_post_tags($edit)) { echo ", "; }?></textarea><br />
		
				<label for="recent_tags">Recently Used Tags</label><p id="recent_tags"><? echo drizzo_recent_tags(); ?></p>

				<p class="right"><input type="button" onclick="history.go(-1)" value="Cancel" class="submit" /><input type="submit" name="edit_submit" value="Publish" class="submit" /></p>

			</div>
	
			<div id="options">
				
				<div id="image_preview">
					<h3>The Image</h3>
					<img src="<? echo "/" . str_replace(root_dir,'',$this_item); ?>" alt="<? echo $the_post['title']; ?>" />
				</div>
		
				<? drizzo_post_authors_dropdown(); ?>
		
				<input type="hidden" name="type" value="image" />
				<input type="hidden" name="status" value="publish" />
				<input type="hidden" name="ID" value="<? echo $the_post['ID']; ?>" />
				<input type="hidden" name="posted_date" value="<? echo $the_post['posted_date_raw']; ?>" />
				<input type="hidden" name="save_location" value="<? echo dirname(str_replace(root_dir,'',$this_item)); ?>" />
		
				<? drizzo_post_comment_statuses_dropdown(); ?>
		
				<? drizzo_edit_status(); ?>
		
				<? if($edit) { echo "<h3>Previous Revisions</h3>\n" . drizzo_warehouse_revisions_list(); } ?>

			</div>

			</form>
<?
		}
	} elseif($action == 'delete') {
		if($_POST) {
			echo drizzo_media_delete();
		} else {
			$fileinfo = pathinfo($this_item);
			$filename = str_replace("." . $fileinfo['extension'],"",$fileinfo['basename']);
			if(drizzo_media_is_file_type('image',$this_item)) {
				echo "\t<img src=\"" . domain . str_replace(root_dir,"",$this_item) . "\" alt=\"" . basename($this_item) . "\" />";
			}
?>
			<form action="" method="post">
			<p><strong>Are you sure you want to delete "<? echo $filename; ?>"?</strong></p>
			<input type="hidden" name="ID" value="<? echo $id; ?>" />
			<p class="right"><input type="button" onclick="history.go(-1)" value="Cancel" class="submit" /><input type="submit" name="sumbit" value="Delete" class="submit" /></p>
			</form>
<?
		}
	}
	if(count($_GET) == 0 || ($action != null && count($_POST) > 0)) {
		echo drizzo_gallery_list();
	}
?>			
			<br class="clear" />
			
		</div>
<?
	include_once('footer.php');
?>
